'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ChatGroupusersCtrl
 * @description
 * # ChatGroupusersCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ChatGroupusersCtrl', function ($routeParams, $location, RongYService, ChatStatus, DataService, openApi, Util) {
        var vm = this;
        var targetId;
        targetId = $routeParams.id
        vm.userId = $routeParams.userId
        var init = function () {
            var param = {}
            param.flag = 2
            param.id = targetId
            DataService.getData(openApi.getGroupUsers, param).then(function (data) {
                vm.peoplelist = data
            })
        }
        this.goDetail = function (item) {
            $location.path("addressbook/userdetail/" + item.id)
        }
        this.showMore = function () {
            vm.isShowMore = !vm.isShowMore;
            this.showdel = false
        };
        this.hidemore = function () {
            vm.isShowMore = false
        };
        // 添加成员(会话类型由)
        this.addUsers = function () {
            ChatStatus.setTargetId(targetId);
            ChatStatus.setStatus(ChatStatus.UPDATE);
            $location.path("/chat/selectuser")
        };
        this.removeUsers = function () {
            this.showdel = !this.showdel
        }
        this.confirmdel = function (userId) {
            if (navigator.notification) {
                navigator.notification.confirm(
                    '是否删除',
                    vm.checkConfirm(userId),
                    '提示', ['删除', '取消']
                )
            }
        }
        this.checkConfirm = function (userId) {
            return function (btn) {
                if (btn == 1) {
                    var param = {}
                    param.groupId = targetId
                    param.userId = userId
                    RongYService.quitGroup(param).then(function (data) {
                        console.log(data)
                        init()
                    });

                }
            }
        }
        init()
    });
